import request from '@/utils/request'

/**
 * 获取资源列表
 */
export function getResourceList(params?: ResourceQueryParams) {
  return request.get<ResourceFormData[]>('/resources', params)
}

/**
 * 获取资源树
 */
export function getResourceTree(params?: ResourceQueryParams) {
  return request.get<ResourceFormData[]>('/resources/tree', params)
}

/**
 * 获取资源详情
 */
export function getResourceById(id: number) {
  return request.get<ResourceFormData>(`/resources/${id}`)
}

/**
 * 创建资源
 */
export function createResource(data: ResourceCreateRequest) {
  return request.post('/resources', data, {
    successMessage: '创建资源成功'
  })
}

/**
 * 更新资源
 */
export function updateResource(id: number, data: ResourceUpdateRequest) {
  return request.put(`/resources/${id}`, data, {
    successMessage: '更新资源成功'
  })
}

/**
 * 删除资源
 */
export function deleteResource(id: number) {
  return request.delete(`/resources/${id}`, undefined, {
    successMessage: '删除资源成功'
  })
}

/**
 * 批量删除资源
 */
export function batchDeleteResources(ids: number[]) {
  return request.delete('/resources/batch', { ids }, {
    successMessage: '批量删除成功'
  })
}

